﻿﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Script.EnemySystem.EnemyState;
using UnityEngine;

namespace Com.Enemy.EnemySystem.Tools
{
    public class CoolDownSystem
    {
        private readonly CoolDownOrder<CoolDownInfo> coolDownQueue = new CoolDownOrder<CoolDownInfo>(10);

        public IEnumerator UpdateColdDown(float timeScale)
        {
            coolDownQueue.UpdateCoolDown(Time.deltaTime * timeScale);
            yield break;
        }
        public bool HadColdDown(EnemyState state)
        {
            return !coolDownQueue.Contains((int) state);
        }
        
        public void AddColdDownInfo(EnemyState state, float coldDown){
            // Debug.Log(state + "进入冷却状态" + coldDown);
            coolDownQueue.Add(new CoolDownInfo(state, coldDown));
        }

    }
    
    
    public struct CoolDownInfo : ICoolDown<CoolDownInfo>
    {
        public float CoolDown { get; set; }
        public EnemyState State { get; set; }
        

        public int CompareTo(CoolDownInfo other)
        {
            return CoolDown.CompareTo(other.CoolDown);
        }

        public int ItemTag => (int)State;

        public float NowCoolDown
        {
            get => CoolDown;
            set => CoolDown = value;
        }
        
        public CoolDownInfo(EnemyState state, float coolDown)
        {
            State = state;
            CoolDown = coolDown;
        }

    }

}